/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.service;

import br.com.foxline.model.City;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author roniere
 */
@Stateless
public class CityService extends GenericService<City>{

    public CityService() {
        super(City.class);
    }
    
    
   public List<City> autocomplete(String name) {
        List<City> lista = new ArrayList<City>();
        String sql = "Select c from City c where lower(c.name) like lower(:name)";
        Query query = getEntityManager().createQuery(sql).setMaxResults(50);

        if (name != null) {
            query.setParameter("name", "" + name + "%");
        }
        
        
        lista = query.getResultList();
        return lista;
    }
    
   
   
}
